<?php
namespace wow\modelworld;

use \wow\model\dbcon as dbs;
/**
 * 
 * 
 * @Entity
 * @Table(name="command")
 * 
 */
class Command{
	
	
	/**
     * @Id @Column(type="string", name="name")
     */
	public $name;
	
	/**
	 * 
	 * @Column(name="security", type="integer")
	 */
	public $security;
	
	/**
	 * 
	 * @Column(name="help", type="string")
	 */
	public $help;
	
	

	
	public function getSecurityName(){
		$p = \gnomephp\Configuration::get('permission','gmlevels');
		return isset($p[$this->security]) ? $p[$this->security] : $this->security;
	}

	static public function getCommands($realmId, $security = null){
		$em = dbs\WorldDB::getEmFor($realmId);
		
		$qb = $em->getWorldEM()->createQueryBuilder();
		
		$qb->add('select','c')
		->add('from', 'wow\modelworld\Command c');
			
		if ($security !== null){
			$qb->add('where','c.security <= ?1');
			$qb->setParameter(1, $security);
		}
		
		$qb->add('orderBy','c.security DESC, c.name ASC');
		
			
		
		return $qb->getQuery()->getResult();
		
		
	}
	
	
	
	
}
